#include <iostream>
using std::cout;
using std::endl;
using std::cin;
class Point{
public:
    Point(){
        cout<<"Point()"<<endl;
    };
    Point(int x,int y)
        :_x(x)
         ,_y(y){
             cout<<"Point"<<endl;
         }
    ~Point(){
        cout<<"~Point"<<endl;
    }
    void gets(){
        cout<<"x:"<<_x<<"y:"<<_y<<endl;
    }
private:
    int _x=0;
    int _y=10;
};
class Data{

public:
    Data(Point *p)
        :_po(p){
            cout<<"Data"<<endl;
        }
    ~Data(){
        if(_po){
            delete _po;
            _po = nullptr;
        }
        cout<<"~Data"<<endl;
    }
    Point* operator->(){
        return _po;     
    }
    Point& operator*(){
        return *_po;     
    }
private:
    Point *_po;

};
class Third{
public:
    Third(Data *da)
        :_data(da){
            cout<<"Third"<<endl;
        }
    ~Third(){
        delete _data;
        _data = nullptr;
        cout<<"~Third"<<endl;
    }
   // Data* operator->(){ 不能返回指针 只能返回一个引用
   // 是因为引用 是直接返回 一个对象来利用中间层data的->重载
   // 但是如果返回指针
     Data & operator->(){
        return *_data;
    }
     Data & operator*(){
        return *_data;
    }
private:
   Data *_data; 
};
void test0(){
    Data d(new Point());
    
    d->gets();
}
void test1(){
    Third third(new Data(new Point()));
    third->gets();
   (*(*third)).gets();
}
int main()
{
    test1();
    std::cout << "Hello world" << std::endl;
    return 0;
}

